import java.io.*;
import java.util.Scanner;

public class Test {


    public static void main(String[] args)  throws IOException {
        Scanner scanner = new Scanner(System.in);
    }
    public static void main7(String[] args) throws IOException {
        try(Writer writer = new FileWriter("d:/dog111.txt",true)) {
            writer.write(",");
            writer.write("我是追加写的内容啊");
        }
    }
    public static void main6(String[] args) throws IOException {
        try(Reader reader = new FileReader("d:/dog111.txt");) {
            char[] arr = new char[10];
            while (true) {
                int n = reader.read(arr);
                if(n==-1) break;
                for(int i=0;i<n;i++) {
                    System.out.print(arr[i]+" ");
                }
            }
        }
    }



    //-----------------------
    public static void main5(String[] args)  throws IOException{
        //写文件
        try(OutputStream outputStream = new FileOutputStream("d:/dog111.txt",true)) {
            outputStream.write(100);
            outputStream.write(100);
            outputStream.write(100);
            outputStream.write(100);
            outputStream.write(101);
        }
    }

    public static void main4(String[] args) throws IOException{
        //如果优雅的关闭流
        try (InputStream file = new FileInputStream("d:/dog111.txt")){
            byte[] bytes = new byte[1024];
            while (true) {
                int n = file.read(bytes);
                if(n==-1) break;
                for (int i = 0; i < n; i++) {
                    System.out.print((char) bytes[i]+" ");
                }
            }
        }
    }
    public static void main3(String[] args) throws IOException{
        InputStream inputStream = new FileInputStream("d:/dog111.txt");
       try{
           byte[] bytes = new byte[1024];
           while (true) {
               int n = inputStream.read(bytes,0,1024);
               if(n==-1) {
                   break;
               }
               for (int i = 0; i < n; i++) {
                   System.out.printf("%c ",bytes[i]);
               }
           }
       }finally {
           inputStream.close();
       }

    }
    public static void main2(String[] args) throws IOException{
        //二进制读取文件第二种
        InputStream file = new FileInputStream("d:/dog111.txt");
        byte[] bytes = new byte[1024];
        while (true) {
            int n = file.read(bytes);
            if(n==-1) break;
            for (int i = 0; i < n; i++) {
                System.out.printf("%c ",bytes[i]);
            }
            System.out.println();
        }
    }

    public static void main1(String[] args) throws IOException {
        //1.打开文件
        InputStream file = new FileInputStream("d:/dog111.txt");//以二进制打开文件(文件必须存在)
        //2.读文件
        while (true) {
            int n = file.read();
            if(n==-1) {
                System.out.println("文件读取完毕");
                break;
            }
            System.out.printf("%c ",n);
        }

    }
}
